home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Games / ADoom / ADoom_src / st_lib.c < prev    next >
C/C++ Source or Header  |  1998-01-26  |  5KB  |  297 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. //    The status bar widget code.
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24.  
  25. static const char
  26. rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $";
  27.  
  28. #include <ctype.h>
  29.  
  30. #include "doomdef.h"
  31.  
  32. #include "z_zone.h"
  33. #include "v_video.h"
  34.  
  35. #include "m_swap.h"
  36.  
  37. #include "i_system.h"
  38.  
  39. #include "w_wad.h"
  40.  
  41. #include "st_stuff.h"
  42. #include "st_lib.h"
  43. #include "r_local.h"
  44.  
  45.  
  46. // in AM_map.c
  47. extern boolean        automapactive; 
  48.  
  49.  
  50.  
  51.  
  52. //
  53. // Hack display negative frags.
  54. //  Loads and store the stminus lump.
  55. //
  56. patch_t*        sttminus = NULL;
  57.  
  58. void STlib_init(void)
  59. {
  60.     int i;
  61.  
  62.     if ((i = W_CheckNumForName("STTMINUS")) != -1)
  63.         sttminus = (patch_t *) W_CacheLumpNum(i, PU_STATIC);
  64. }
  65.  
  66.  
  67. // ?
  68. void
  69. STlib_initNum
  70. ( st_number_t*        n,
  71.   int            x,
  72.   int            y,
  73.   patch_t**        pl,
  74.   int*            num,
  75.   boolean*        on,
  76.   int            width )
  77. {
  78.     n->x    = x;
  79.     n->y    = y;
  80.     n->oldnum    = 0;
  81.     n->width    = width;
  82.     n->num    = num;
  83.     n->on    = on;
  84.     n->p    = pl;
  85. }
  86.  
  87.  
  88. // 
  89. // A fairly efficient way to draw a number
  90. //  based on differences from the old number.
  91. // Note: worth the trouble?
  92. //
  93. void
  94. STlib_drawNum
  95. ( st_number_t*    n,
  96.   boolean    refresh )
  97. {
  98.  
  99.     int        numdigits = n->width;
  100.     int        num = *n->num;
  101.     
  102.     int        w = SWAPSHORT(n->p[0]->width);
  103.     int        h = SWAPSHORT(n->p[0]->height);
  104.     int        x = n->x;
  105.     
  106.     int        neg;
  107.  
  108.     n->oldnum = *n->num;
  109.  
  110.     neg = num < 0;
  111.  
  112.     if (neg)
  113.     {
  114.     if (numdigits == 2 && num < -9)
  115.         num = -9;
  116.     else if (numdigits == 3 && num < -99)
  117.         num = -99;
  118.     
  119.     num = -num;
  120.     }
  121.  
  122.     // clear the area
  123.     x = n->x - numdigits*w;
  124.  
  125.     if (n->y - ST_Y < 0)
  126.     I_Error("drawNum: n->y - ST_Y < 0");
  127.  
  128.     V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
  129.  
  130.     // if non-number, do not draw it
  131.     if (num == 1994)
  132.     return;
  133.  
  134.     x = n->x;
  135.  
  136.     // in the special case of 0, you draw 0
  137.     if (!num)
  138.     V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
  139.  
  140.     // draw the new number
  141.     while (num && numdigits--)
  142.     {
  143.     x -= w;
  144.     V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
  145.     num /= 10;
  146.     }
  147.  
  148.     // draw a minus sign if necessary
  149.     if (neg && sttminus != NULL)
  150.     V_DrawPatch(x - 8, n->y, FG, sttminus);
  151. }
  152.  
  153.  
  154. //
  155. void
  156. STlib_updateNum
  157. ( st_number_t*        n,
  158.   boolean        refresh )
  159. {
  160.     if (*n->on) STlib_drawNum(n, refresh);
  161. }
  162.  
  163.  
  164. //
  165. void
  166. STlib_initPercent
  167. ( st_percent_t*        p,
  168.   int            x,
  169.   int            y,
  170.   patch_t**        pl,
  171.   int*            num,
  172.   boolean*        on,
  173.   patch_t*        percent )
  174. {
  175.     STlib_initNum(&p->n, x, y, pl, num, on, 3);
  176.     p->p = percent;
  177. }
  178.  
  179.  
  180.  
  181.  
  182. void
  183. STlib_updatePercent
  184. ( st_percent_t*        per,
  185.   int            refresh )
  186. {
  187.     if (refresh && *per->n.on)
  188.     V_DrawPatch(per->n.x, per->n.y, FG, per->p);
  189.     
  190.     STlib_updateNum(&per->n, refresh);
  191. }
  192.  
  193.  
  194.  
  195. void
  196. STlib_initMultIcon
  197. ( st_multicon_t*    i,
  198.   int            x,
  199.   int            y,
  200.   patch_t**        il,
  201.   int*            inum,
  202.   boolean*        on )
  203. {
  204.     i->x    = x;
  205.     i->y    = y;
  206.     i->oldinum     = -1;
  207.     i->inum    = inum;
  208.     i->on    = on;
  209.     i->p    = il;
  210. }
  211.  
  212.  
  213.  
  214. void
  215. STlib_updateMultIcon
  216. ( st_multicon_t*    mi,
  217.   boolean        refresh )
  218. {
  219.     int            w;
  220.     int            h;
  221.     int            x;
  222.     int            y;
  223.  
  224.     if (*mi->on
  225.     && (mi->oldinum != *mi->inum || refresh)
  226.     && (*mi->inum!=-1))
  227.     {
  228.     if (mi->oldinum != -1)
  229.     {
  230.         x = mi->x - SWAPSHORT(mi->p[mi->oldinum]->leftoffset);
  231.         y = mi->y - SWAPSHORT(mi->p[mi->oldinum]->topoffset);
  232.         w = SWAPSHORT(mi->p[mi->oldinum]->width);
  233.         h = SWAPSHORT(mi->p[mi->oldinum]->height);
  234.  
  235.         if (y - ST_Y < 0)
  236.         I_Error("updateMultIcon: y - ST_Y < 0");
  237.  
  238.         V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  239.     }
  240.     V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
  241.     mi->oldinum = *mi->inum;
  242.     }
  243. }
  244.  
  245.  
  246.  
  247. void
  248. STlib_initBinIcon
  249. ( st_binicon_t*        b,
  250.   int            x,
  251.   int            y,
  252.   patch_t*        i,
  253.   boolean*        val,
  254.   boolean*        on )
  255. {
  256.     b->x    = x;
  257.     b->y    = y;
  258.     b->oldval    = 0;
  259.     b->val    = val;
  260.     b->on    = on;
  261.     b->p    = i;
  262. }
  263.  
  264.  
  265.  
  266. void
  267. STlib_updateBinIcon
  268. ( st_binicon_t*        bi,
  269.   boolean        refresh )
  270. {
  271.     int            x;
  272.     int            y;
  273.     int            w;
  274.     int            h;
  275.  
  276.     if (*bi->on
  277.     && (bi->oldval != *bi->val || refresh))
  278.     {
  279.     x = bi->x - SWAPSHORT(bi->p->leftoffset);
  280.     y = bi->y - SWAPSHORT(bi->p->topoffset);
  281.     w = SWAPSHORT(bi->p->width);
  282.     h = SWAPSHORT(bi->p->height);
  283.  
  284.     if (y - ST_Y < 0)
  285.         I_Error("updateBinIcon: y - ST_Y < 0");
  286.  
  287.     if (*bi->val)
  288.         V_DrawPatch(bi->x, bi->y, FG, bi->p);
  289.     else
  290.         V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  291.  
  292.     bi->oldval = *bi->val;
  293.     }
  294.  
  295. }
  296.  
  297.